/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JDialogDirektori.java
 *
 * Created on 07 Mei 10, 17:36:33
 */

package Riset1;

import amd.database.*;
import java.io.File;
import amd.core.data.DocumentPdf;
import Classes.*;

/**
 *
 * @author Presario
 */
public class JDialogDirektori extends javax.swing.JDialog {
      static HasilExtract inv = null;

    /** Creates new form JDialogDirektori */
    public JDialogDirektori(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFileChooser1 = new javax.swing.JFileChooser();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jFileChooser1.setCurrentDirectory(new java.io.File("C:\\"));
            jFileChooser1.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
            jFileChooser1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jFileChooser1ActionPerformed(evt);
                }
            });

            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap())
            );

            pack();
        }// </editor-fold>//GEN-END:initComponents

    private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {
/*
    private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFileChooser1ActionPerformed
  */
    // TODO add your handling code here:
      System.out.println(evt.getActionCommand());
        if(evt.getActionCommand().startsWith("App"))
        {
            ConnectDB conn=null;
            try {
                conn = new ConnectDB("jdbc:mysql://localhost:3306/db_amd_lsa", "root", "");
            } catch (Exception ex) {
                System.out.println(ex);
                System.exit(0);
            }
            System.out.println("===> File Selected=");
            File fout = new File("c:/aTargetPDF/");
            System.out.println(jFileChooser1.getSelectedFile());
//            DocumentPdf dPdf = DocExtractor.extractAllDocument(jFileChooser1.getSelectedFile(), fout);
//            hMain = DocExtractor.extractAllDocument(jFileChooser1.getSelectedFile(), fout);
//            hMain = DocExtractor.extractAllDocument(jFileChooser1.getSelectedFile(), fout);
//            inv = DocExtractor.extractAllDocument(jFileChooser1.getSelectedFile(), fout, conn);
//            DocExtractor.insertToInvertedIndex(dPdf);
            DocExtractor.extractAllDocument(jFileChooser1.getSelectedFile(), fout, conn);
//            if(inv!=null)
//            {
//                System.out.println("===Ini Invertednya===");
//                Node n[] = inv.getTerms();
//                Doc d[] = inv.getDocs();
//                TermDoc t[][] = inv.getTermDocs();
//                System.out.println("");
//                for(int j=0; j<inv.getDocs().length; j++) {
//                        System.out.print(space(0)+d[j].getId_Doc());
//                }
//                System.out.println("");
//                int i = 0;
//                while(n[i] != null && i < n.length) {
//                    int count =0;
//                    for(int j=0; j<d.length; j++) {
//                        if(t[i][j].getFreq()!=0)
//                            count++;
//                    }
//                    n[i].setJdoc(count);
//                    i++;
//                }
////                inv.HitungBobot();
//                i=0;
//                while(n[i] != null && i < n.length) {
//                    System.out.print(n[i].getT()+space(n[i].getT().length()));
//                    for(int j=0; j<d.length; j++) {
//                        System.out.print(t[i][j].getFreq());
//                        System.out.print("    "+t[i][j].getBobot());
//                        System.out.print(space(String.valueOf(t[i][j].getBobot()).length()));
//                    }
//                    System.out.print(n[i].getJdoc());
//                    System.out.print("\n");
//                    i++;
//                }
////                TermDoc sbb[] = SearchTerm.Search("model",inv);
//            }
        }
        else
            System.out.print("===> cancelSelection <===");
        JDialogDirektori.this.dispose();

    }//GEN-LAST:event_jFileChooser1ActionPerformed

    public String space(int l) {
        String s="";
        for(int i=0; i<15-l; i++) {
            s=s+" ";
        }

        return s;
    }

    /**
    * @param args the command line arguments
    */
    public void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFileChooser jFileChooser1;
    // End of variables declaration//GEN-END:variables

}
